package com.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class UserAspect {

    @Before("@annotation(com.example.demo.controller.MyAspectHa)")
    public void doBefore(){
        System.out.println("进入方法之前");
    }


    @After("@annotation(com.example.demo.controller.MyAspectHa)")
    public void doAfter(){
        System.out.println("方法之后执行");
    }

    @Around("@annotation(com.example.demo.controller.MyAspectHa)")
    public Object loginTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start=System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long end=System.currentTimeMillis();
        log.info("方法耗时间的长度:{}",end-start);
        return proceed;
    }
}
